package com.neusoft.yuejian_01.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.neusoft.yuejian_01.R;
import com.neusoft.yuejian_01.javabean.CommentListBean;
import com.neusoft.yuejian_01.model.ConstPhoto;
import com.neusoft.yuejian_01.viewHolder.CommentListViewHolder;

import java.util.ArrayList;
import java.util.List;

import it.sephiroth.android.library.picasso.Picasso;

/**
 * Created by MARIA on 2017/10/14.
 */

public class CommentListAdapter  extends RecyclerView.Adapter {


    private List<CommentListBean> Commentlist = new ArrayList<>();
    private Context context;
    private LayoutInflater layoutInflater;//使用了LayoutInflater来载入布局界面
    public CommentListAdapter(Context context, List<CommentListBean> Commentlist) {
        this.context = context;
        layoutInflater = LayoutInflater.from(context);
        this.Commentlist.addAll(Commentlist);

    }


    @Override

    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View itemView=layoutInflater.inflate(R.layout.item_comment,parent,false);
        CommentListViewHolder holder=new CommentListViewHolder(itemView);
        return holder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {

        CommentListViewHolder commentListViewHolder=(CommentListViewHolder) holder;
        final CommentListBean commentListBean =Commentlist.get(position);
        String touxiang= ConstPhoto.BASE_URL+ConstPhoto.SetPictureFile+ commentListBean.getU_pic();
        String username=commentListBean.getU_name();
        String cinfo=commentListBean.getCo_info();
        String ctime=commentListBean.getCreatetime();
        Picasso.with(context)
                .load(touxiang)
                .into(CommentListViewHolder.c_pic);
        commentListViewHolder.c_Name.setText(username);
        commentListViewHolder.c_Info.setText(cinfo);
        commentListViewHolder.c_time.setText(ctime);

    }

    @Override
    public int getItemCount() {
        return Commentlist.size();
    }
}
